﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SheZhiDGH.aspx.cs" Inherits="Web.Pages.QuShui.DiXiaS._2.YongHuGL.SheZhiDGH" Theme="Default"%>

<%@ Register Assembly="DevExpress.Web.v15.2, Version=15.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../../../../JS/AddEditCancel.js"></script>
    <script src="../../../../JS/jquery.js"></script>
    <script type="text/javascript">

        function display(op, id) {
            hdCollection.Set("ID", id);
            if (op == "add") {
                btnAdd.SetVisible(false);
                lblOperateTip.SetText("添加");
                txtBianHao.SetText("");
                txtBianHao.SetEnabled(true);
                txtMingCheng.SetText("");
                txtMingCheng.SetEnabled(true);
                listCover(true, "divList");
                $("#GridViewContentTable").show();
                txtBianHao.Focus();
            }
            else if (op == "edit") {
                btnAdd.SetVisible(false);
                lblOperateTip.SetText("修改");
                txtBianHao.SetEnabled(false);
                txtMingCheng.SetEnabled(true);
                listCover(true, "divList");
                $("#GridViewContentTable").show();
                ASPxCallback1.PerformCallback("info");
            }
            else {
                $("#GridViewContentTable").hide();
                btnAdd.SetVisible(true);
                listCover(false, "divList");
            }
        }

        function del(id) {
            hdCollection.Set("ID", id);
            if (confirm("确认删除吗？")) {
                ASPxCallback1.PerformCallback("del");
            }
            else {
                hdCollection.Set("ID", -1);
            }
        }

        function save() {
            if (txtBianHao.GetText() == "") {
                alert("用户号，不能为空！");
                txtBianHao.Focus();
                return;
            }
            if (!isAllNum(txtBianHao.GetText())) {
                alert("你输入的用户号格式不正确，请输入数字类型！");
                txtBianHao.Focus();
                return;
            }
            if (txtMingCheng.GetText() == "") {
                alert("用户名不能为空！");
                txtMingCheng.Focus();
                return;
            }
            ASPxCallback1.PerformCallback("save");
        }

        function SearchYHM() {
            
           // hdCollection.Set("ID", yhh);
            ASPxCallback1.PerformCallback("yhm");
        }

        function ASPxCallback1Complete(rs) {
            var arr = rs.split('|');
            var type = arr[0];
            var state = arr[1];
            var specialIdentity = arr[2];
            var msg = arr[3].split('-');
            if (msg[0] == 'True') {
                if (type!='yhm') {
                    alert(msg[1]);
                    txtBianHao.Focus();
                }
                
            }
            hdCollection.Set("type", type);
            if (state == 'True') {
                if (type == "info") {
                    //加载信息
                    txtBianHao.SetText(arr[4]);
                    txtMingCheng.SetText(arr[5]);
                    txtBianHao.Focus();
                }
                else if (type == "del") {
                    gvList.PerformCallback();
                }
                else if (type == "save") {

                    display("init", -1);
                    //记录当前操作对象,用于刷新列表后定位
                    hdCollection.Set("OperateID", specialIdentity);
                    gvList.PerformCallback();
                }
                else if (type == "yhm") {
                    txtMingCheng.SetText(msg[1]);
                }
            }
            else {

            }
        }
        function begincall() {
            loadpanel1.Show();
        }
        function endcall() {
            loadpanel1.Hide();
            //定位添加或修改的记录
            var oid = hdCollection.Get("OperateID");
            var index = -1;
            if (oid != -1 && typeof (oid) != undefined) {
                for (var i = 0; i < gvList.GetVisibleRowsOnPage() ; i++) {
                    if (gvList.GetRowKey(i) == oid) {
                        index = i;
                    }
                }
                if (index != -1) {
                    gvList.SetFocusedRowIndex(index);
                    gvList.MakeRowVisible(index);
                    hdCollection.Set("OperateID", -1);
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div class="tabletitle1" align="center">
           设置代灌户
        </div>
        <dx:ASPxHiddenField ID="hdCollection" ClientInstanceName="hdCollection" runat="server"></dx:ASPxHiddenField>
        <dx:ASPxCallback ID="ASPxCallback1" ClientInstanceName="ASPxCallback1" runat="server" OnCallback="ASPxCallback1_Callback" ClientSideEvents-CallbackComplete="function(s,e){ASPxCallback1Complete(e.result);}"></dx:ASPxCallback>
        <dx:ASPxLoadingPanel ID="ASPxLoadingPanel1" ClientInstanceName="loadpanel1" runat="server" ContainerElementID="gvList" Modal="true" Theme="Metropolis" ShowImage="false" Text="加载中"></dx:ASPxLoadingPanel>
        <div style="height: 3px;"></div>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <table style="width: 30%; margin: auto; float:left;">
                    <tr>
                        <td align="left" style="width: 18%">年份：
                        </td>
                        <td align="left">
                            <dx:ASPxComboBox ID="cmbNianF1"  runat="server" Width="60%" OnSelectedIndexChanged="cmbNianF1_SelectedIndexChanged" AutoPostBack="true">
                            </dx:ASPxComboBox>
                        </td>
                    </tr>
                </table>
                <div id="divList" align="center">
                    <div>
                        <dx:ASPxGridView ID="gvList" ClientInstanceName="gvList" runat="server" AutoGenerateColumns="False" KeyFieldName="ID" Theme="Aqua1" Width="100%" OnCustomCallback="gvList_CustomCallback">
                            <Columns>
                                <dx:GridViewDataTextColumn FieldName="S_YONGHUH" Caption="用户号" Width="20%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="S_YONGHUM" Caption="用户名" Width="30%">
                                </dx:GridViewDataTextColumn>
                               <%-- <dx:GridViewDataTextColumn Width="5%">
                                    <DataItemTemplate>
                                        <a href="#" onclick="display('edit','<%#Eval("ID")%>')">修改</a>
                                    </DataItemTemplate>
                                </dx:GridViewDataTextColumn>--%>
                                <dx:GridViewDataTextColumn Width="5%">
                                    <DataItemTemplate>
                                        <a href="#" onclick="del('<%#Eval("ID")%>')">删除</a>
                                    </DataItemTemplate>
                                </dx:GridViewDataTextColumn>
                            </Columns>
                            <Settings VerticalScrollableHeight="315" VerticalScrollBarMode="Auto" />
                            <ClientSideEvents Init="function(s,e){AdjustSize(400,gvList);}" BeginCallback="function(s,e){begincall();}" EndCallback="function(s,e){endcall();}" />
                        </dx:ASPxGridView>
                    </div>
                    <div style="height: 3px;"></div>
                    <div style="text-align: right">
                        <hr />
                        <dx:ASPxButton ID="btnAdd" ClientInstanceName="btnAdd" runat="server" Text="添加" AutoPostBack="false" ClientSideEvents-Click="function(s,e){display('add',-1)}" UseSubmitBehavior="false">
                        </dx:ASPxButton>
                    </div>
                    <div id="GridViewContentTable" style="display: none;">
                        <div class="tabletitle1" align="center">
                            <dx:ASPxLabel ID="lblOperateTip" runat="server" ClientInstanceName="lblOperateTip" Text="添加"></dx:ASPxLabel>
                        </div>
                        <table style="width: 80%; margin: auto;">
                            <tr>
                                 <td align="right" style="width: 40%">年份：
                                </td>
                                <td>
                                    <dx:ASPxComboBox ID="cmbNianF2" ClientInstanceName="cmbNianF2" runat="server" Width="60%" ClientEnabled="false">
                                        <%--<ClientSideEvents KeyPress="function(s,e){OnKeyNext(txtBianHao);}" />--%>
                                    </dx:ASPxComboBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="right" style="width: 40%">用户号：
                                </td>
                                <td>
                                    <dx:ASPxTextBox ID="txtBianHao" ClientInstanceName="txtBianHao" runat="server" Width="60%" MaxLength="15">
                                        <ClientSideEvents KeyPress="function(s,e){var key = event.keyCode;if( key==13){SearchYHM();}}"/>
                                    </dx:ASPxTextBox>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">用户名：
                                </td>
                                <td>
                                    <dx:ASPxTextBox ID="txtMingCheng" ClientInstanceName="txtMingCheng" runat="server" Width="100%" MaxLength="30">
                                        
                                    </dx:ASPxTextBox>
                                </td>
                            </tr>
                        </table>
                        <table id="GridViewButtonTable" runat="server" style="width: 100%">
                            <tr>
                                <td>
                                    <hr />
                                </td>
                            </tr>
                            <tr>
                                <td style="text-align: right;">
                                    <dx:ASPxButton ID="btnSave" ClientInstanceName="btnSave" runat="server" Text="保存" UseSubmitBehavior="false" AutoPostBack="false">
                                        <ClientSideEvents Click="function(s, e) {save(); }" />
                                    </dx:ASPxButton>
                                    <dx:ASPxButton ID="btnCancel" runat="server" Text="放弃" AutoPostBack="false" UseSubmitBehavior="false">
                                        <ClientSideEvents Click="function(s,e){display('init',-1);}" />
                                    </dx:ASPxButton>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>